package cn.yangliu.nacos.comm.config.security.handler;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.yangliu.nacos.comm.enums.GlobalResultCode;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;


/**
 * The interface Security authentication success handler.
 *
 * @author 问道于盲
 */
public class SecurityAuthenticationSuccessHandler
        implements AuthenticationSuccessHandler, SecurityHandler {


    /**
     * Called when a user has been successfully authenticated.
     *
     * @param request        the request which caused the successful authentication
     * @param response       the response
     * @param authentication the <tt>Authentication</tt> object which was                       created during
     *       the authentication process.
     * @throws IOException      the io exception
     * @throws ServletException the servlet exception
     */
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request,
                                        HttpServletResponse response, Authentication authentication)
            throws IOException, ServletException {

		handle(request, response, HttpStatus.OK, GlobalResultCode.SUCCESS, null, authentication.getPrincipal());
    }

}
